Skip to content

feat(resolve): bind Tauri commands to their invoke call sites - #217

Merged
sunerpy merged 1 commit into
mainfrom
feat/tier4-tauri-resolver
Aug 20, 2026
Merged

sunerpy merged 1 commit into
mainfrom
feat/tier4-tauri-resolver

Conversation

@sunerpy

@sunerpy sunerpy commented Aug 20, 2026

Copy link
Copy Markdown
Owner

Tier 4 item 10 of the post-v1.5.0 upstream sync (#1543). A #[tauri::command] read as dead code — the IPC boundary was absent from the graph:

$ codegraph callers get_mcp_port
No callers found for "get_mcp_port"       # zero .ts -> .rs edges

What it does

TauriResolver emits one namespaced reference per literal-argument invoke call site and binds it to the command claiming that wire name, accepting both the snake_case attribute name and the camelCase spelling tauri-specta generates.

An edge is built only when exactly one command claims the name; a name claimed by a second, different target is poisoned permanently. That rule is the only protection available here — Language::Rust returns None from language_family, so crosses_known_family never fires for a Rust target, and Calls bypasses those gates regardless.

Both text scans are masked, with different burdens of proof

On the TypeScript side the extractor already discriminates every shape, so the mask is held to agreeing with it. Measured on one .tsx fixture carrying all six shapes:

shape edges
// invoke('fake') 0
"invoke('fake')" 0
`invoke('fake')` 0
/invoke\('fake'\)/ 0
client.invoke('fake') 0
await invoke('get_mcp_port') 1

On the Rust side nothing else discriminates, so the mask is the sole defense. Without it, a commented-out or raw-string copy of the attribute promotes the real unattributed function of the same name — those copies mint no node, so the same-file/same-name join has exactly one candidate and it is the wrong one:

// #[tauri::command] fn fake() -> u16 { 0 }        ← comment
const DOC: &str = r#"#[tauri::command]
fn fake() -> u16 { 1 }"#;                          ← raw string
fn fake() -> u16 { 42 }                            ← real, UNattributed

measured: edges to fake = 0,  edges to get_mcp_port = 1,  callers = 1

Pre-fix that adversarial fixture produced 6 fabricated edges where the correct answer is one. The same mask also keeps this repository from detecting itself as a Tauri project off the literal in the resolver's own source — the raw scan finds 2 files, the masked scan finds 0.

Negatives cover nested block comments, r##/br##, byte strings, char-versus-lifetime, and the tauri::commandant token-boundary collision, each with a roster key-set test and an end-to-end edge-count test.

Deliberately out of scope

References are file-granular, so callers names the calling file rather than the enclosing function: reconstructing that id is unsafe when a call site may sit in an arrow function, a class method, or an object literal that mints no node at all. invoke(cmdName), template-literal names, generate_handler! registration (so an attributed-but-unregistered command still gets an edge, asserted deliberately), and the typed commands.* path are not handled.

Verification

  • make ci green: 133 suites / 3371 passed / 0 failed (baseline 132 / 3304).
  • EXTRACTION_VERSION 7 → 8, three edits as the plan required; CURRENT_STORAGE_PROTOCOL stays 2; no new EdgeKind, no schema change.
  • reference/ untouched; erlang's 2 legitimate recursive calls self-edges intact; tests/frameworks.rs zero diff (its MockContext supplies no .rs file, so all four probes miss and its React-only assertion stays true).
  • F3 twin index — same tree, same binary, one untracked tauri.conf.json apart — diff empty, framework=0, tauri_ns=0, on a 582-file snapshot taken with git ls-files --cached --others --exclude-standard so the new untracked files are actually in it.
  • The version bump is load-bearing, proven across two binaries: with it, 2 reindexed, 0 skipped → 2 edges at version 8; without it, 0 reindexed, 2 skipped → 0 edges, version 7. A v7 index would have kept skipping unchanged files forever.

Three deviations from the plan, each measured

  1. The plan's ref-count criteria inspected a table the rows are deleted from. resolve_and_persist calls delete_resolved_rows (resolver.rs:1416), so tauri:invoke:% in unresolved_refs reads 0 post-pipeline and those assertions passed vacuously on an empty set. Re-expressed on edges, with an index_without_resolve harness for the in-suite lexical comparison.
  2. The nested-comment negative could not fail with the plan's bytes — the attribute sat before the inner */, so only still comment */ leaked. Strengthened to /* outer /* inner */ #[tauri::command]….
  3. The token-boundary case needed a detection test, not a roster test — on the roster side the structural ]/( requirement already rejects commandant, so the original probe broke nothing.

The plan cleared four review rounds and ten blockers. One of those blockers was mine and wrong: I demanded the design anchor on the extractor's stored refs, which is impossible at this tier — FrameworkExtractionContext is { project_root, godot_dsl } and ResolutionContext has zero ref-facing methods.

A `#[tauri::command]` read as dead code: nothing connected the Rust function to
the `invoke('name')` that calls it, so `callers get_mcp_port` answered "No
callers found" for a command the frontend used on every launch. The IPC boundary
was simply absent from the graph.

A TauriResolver now spans it. It emits one namespaced reference per
literal-argument `invoke` call site and binds it to the command whose wire name
matches, accepting both the snake_case attribute name and the camelCase spelling
`tauri-specta` generates. An edge is built only when exactly one command claims
the name; a name claimed twice is poisoned permanently, so an ambiguous roster
yields no edge rather than a guess. That rule is the only protection available
here, because Rust has no language family and `Calls` bypasses the cross-family
gates regardless.

Both text scans are lexically masked, and each mask carries a different burden of
proof. On the TypeScript side the extractor already discriminates every shape, so
the mask is held to agreeing with it: a comment, a string, a template literal, a
regex literal and a `client.invoke(...)` member call each contribute nothing,
while the one real call contributes one edge. On the Rust side nothing else
discriminates, so the mask is the only defense — without it a commented-out or
raw-string copy of the attribute promotes the real unattributed function of the
same name, which turns a plain helper into a command and fabricates an edge to
it. The same mask keeps this repository from detecting itself as a Tauri project
off the literal in the resolver's own source.

References are file-granular, so `callers` names the calling file rather than the
enclosing function: reconstructing that id is unsafe when a call site may sit in
an arrow function, a class method, or an object literal that mints no node at
all. `invoke(cmdName)`, template-literal names, `generate_handler!` registration
and the typed `commands.*` binding path are deliberately out of scope.

EXTRACTION_VERSION 7 -> 8: the references are persisted, so a v7 index would
otherwise keep skipping unchanged files and never gain them.
@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.17817% with 85 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/codegraph-resolve/src/frameworks/tauri.rs 93.17% 85 Missing ⚠️

❌ Your patch check has failed because the patch coverage (93.17%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #217      +/-   ##
==========================================
- Coverage   95.30%   95.28%   -0.03%     
==========================================
  Files         139      140       +1     
  Lines       76041    77287    +1246     
==========================================
+ Hits        72472    73642    +1170     
- Misses       3569     3645      +76     
Files with missing lines Coverage Δ
crates/codegraph-resolve/src/frameworks/mod.rs 100.00% <100.00%> (ø)
crates/codegraph-store/src/index_state.rs 83.33% <ø> (ø)
crates/codegraph-resolve/src/frameworks/tauri.rs 93.17% <93.17%> (ø)

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sunerpy
sunerpy merged commit 4ef013b into main Aug 20, 2026
7 checks passed
@sunerpy
sunerpy deleted the feat/tier4-tauri-resolver branch August 20, 2026 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant